package web;

import bean.User;
import impl.UserDaoImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/Reg")
public class RegServlet extends HttpServlet {
    private int us ;
    private UserDaoImpl userDao = new UserDaoImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doGet(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");

        String name = req.getParameter("username");
        String pwd = req.getParameter("password");
        us = userDao.setUserName(name,pwd);
        if(us>0){
            req.getRequestDispatcher("/Login.jsp").forward(req,resp);
        }else {
            req.getRequestDispatcher("/Reg.jsp").forward(req,resp);
        }
    }
}
